package com.jx.dao;

import com.jx.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户数据
     * @param phone
     * @return
     */
    @Select("select * from user where phone = #{phone}")
    User findByPhone(String phone);

    /**
     * 用户注册
     * @param user
     * @return
     */
    @Insert("insert into user (username,password,phone,token,salt) values (#{phone}, #{password}, #{phone}, #{token}, #{salt})")
    Integer userRegister(User user);

    /**
     * 登录
     * @param user
     * @return
     */
    @Select("select * from user where phone = #{phone} and password = #{password}")
    User userLogin(User user);

    /**
     * 根据token查询用户信息
     * @param token
     * @return
     */
    @Select("select * from user where token = #{token}")
    User getUserInfoByToken(String token);

    /**
     * 根据id删除用户
     * @param id
     * @return
     */
    @Delete("delete from user where id = #{id}")
    Integer deleteUserById(Integer id);

}
